<template>
    <a-drawer
        :title="formData.kkdm ? '编辑选课重修' : '增加选课重修'"
        :width="600"
        :visible="visible"
        :destroy-on-close="true"
        :footer-style="{ textAlign: 'right' }"
        @close="onClose"
    >
        <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
            <a-form-item label="学号：" name="xh">
                <a-input v-model:value="formData.xh" placeholder="请输入学号" allow-clear />
            </a-form-item>
            <a-form-item label="学生姓名：" name="xm">
                <a-input v-model:value="formData.xm" placeholder="请输入学生姓名" allow-clear />
            </a-form-item>
            <a-form-item label="班级代码：" name="bjdm">
                <a-input v-model:value="formData.bjdm" placeholder="请输入班级代码" allow-clear />
            </a-form-item>
            <a-form-item label="班级名称：" name="bjmc">
                <a-input v-model:value="formData.bjmc" placeholder="请输入班级名称" allow-clear />
            </a-form-item>
            <a-form-item label="学年学期：" name="xnxq01id">
                <a-input v-model:value="formData.xnxq01id" placeholder="请输入学年学期" allow-clear />
            </a-form-item>
            <a-form-item label="学年：" name="xn">
                <a-input v-model:value="formData.xn" placeholder="请输入学年" allow-clear />
            </a-form-item>
            <a-form-item label="学期：" name="xq">
                <a-input v-model:value="formData.xq" placeholder="请输入学期" allow-clear />
            </a-form-item>
            <a-form-item label="教工号：" name="jszgh">
                <a-input v-model:value="formData.jszgh" placeholder="请输入教工号" allow-clear />
            </a-form-item>
            <a-form-item label="教师姓名：" name="jsxm">
                <a-input v-model:value="formData.jsxm" placeholder="请输入教师姓名" allow-clear />
            </a-form-item>
            <a-form-item label="课程代码：" name="kcdm">
                <a-input v-model:value="formData.kcdm" placeholder="请输入课程代码" allow-clear />
            </a-form-item>
            <a-form-item label="课程专业名称：" name="kczwmc">
                <a-input v-model:value="formData.kczwmc" placeholder="请输入课程专业名称" allow-clear />
            </a-form-item>
            <a-form-item label="星期几：" name="xqj">
                <a-input v-model:value="formData.xqj" placeholder="请输入星期几" allow-clear />
            </a-form-item>
            <a-form-item label="时间段：" name="ddj">
                <a-input v-model:value="formData.ddj" placeholder="请输入时间段" allow-clear />
            </a-form-item>
            <a-form-item label="时间段序号：" name="sjdxh">
                <a-input v-model:value="formData.sjdxh" placeholder="请输入时间段序号" allow-clear />
            </a-form-item>
            <a-form-item label="结束时间序号：" name="jssjxh">
                <a-input v-model:value="formData.jssjxh" placeholder="请输入结束时间序号" allow-clear />
            </a-form-item>
            <a-form-item label="教室编号：" name="jsbh">
                <a-input v-model:value="formData.jsbh" placeholder="请输入教室编号" allow-clear />
            </a-form-item>
            <a-form-item label="教室名称：" name="jsmc">
                <a-input v-model:value="formData.jsmc" placeholder="请输入教室名称" allow-clear />
            </a-form-item>
            <a-form-item label="教学楼：" name="lh">
                <a-input v-model:value="formData.lh" placeholder="请输入教学楼" allow-clear />
            </a-form-item>
            <a-form-item label="起始周：" name="qsz">
                <a-input v-model:value="formData.qsz" placeholder="请输入起始周" allow-clear />
            </a-form-item>
            <a-form-item label="结束周：" name="jsz">
                <a-input v-model:value="formData.jsz" placeholder="请输入结束周" allow-clear />
            </a-form-item>
            <a-form-item label="单双周：" name="dsz">
                <a-input v-model:value="formData.dsz" placeholder="请输入单双周" allow-clear />
            </a-form-item>
            <a-form-item label="课表ID：" name="jx0408id">
                <a-input v-model:value="formData.jx0408id" placeholder="请输入课表ID" allow-clear />
            </a-form-item>
            <a-form-item label="课堂名称：" name="ktmc">
                <a-input v-model:value="formData.ktmc" placeholder="请输入课堂名称" allow-clear />
            </a-form-item>
            <a-form-item label="教学班号：" name="xx04id">
                <a-input v-model:value="formData.xx04id" placeholder="请输入教学班号" allow-clear />
            </a-form-item>
            <a-form-item label="教师类型码：" name="jslxm">
                <a-input v-model:value="formData.jslxm" placeholder="请输入教师类型码" allow-clear />
            </a-form-item>
            <a-form-item label="教师类型：" name="jslx">
                <a-input v-model:value="formData.jslx" placeholder="请输入教师类型" allow-clear />
            </a-form-item>
            <a-form-item label="总学时：" name="zxs">
                <a-input v-model:value="formData.zxs" placeholder="请输入总学时" allow-clear />
            </a-form-item>
            <a-form-item label="学分：" name="xf">
                <a-input v-model:value="formData.xf" placeholder="请输入学分" allow-clear />
            </a-form-item>
            <a-form-item label="课程通识名称：" name="kctxmc">
                <a-input v-model:value="formData.kctxmc" placeholder="请输入课程通识名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程属性名称：" name="kcsxmc">
                <a-input v-model:value="formData.kcsxmc" placeholder="请输入课程属性名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程性质名称：" name="kcxzmc">
                <a-input v-model:value="formData.kcxzmc" placeholder="请输入课程性质名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程辅主类型：" name="kcfalx">
                <a-input v-model:value="formData.kcfalx" placeholder="请输入课程辅主类型" allow-clear />
            </a-form-item>
            <a-form-item label="上课教师职称：" name="skjszc">
                <a-input v-model:value="formData.skjszc" placeholder="请输入上课教师职称" allow-clear />
            </a-form-item>
            <a-form-item label="选课方式：" name="xkfs">
                <a-input v-model:value="formData.xkfs" placeholder="请输入选课方式" allow-clear />
            </a-form-item>
            <a-form-item label="考试方式代码：" name="ksfsdm">
                <a-input v-model:value="formData.ksfsdm" placeholder="请输入考试方式代码" allow-clear />
            </a-form-item>
            <a-form-item label="考试方式名称：" name="ksfsmc">
                <a-input v-model:value="formData.ksfsmc" placeholder="请输入考试方式名称" allow-clear />
            </a-form-item>
            <a-form-item label="上课校区代码：" name="skxqdm">
                <a-input v-model:value="formData.skxqdm" placeholder="请输入上课校区代码" allow-clear />
            </a-form-item>
            <a-form-item label="上课校区名称：" name="skxqmc">
                <a-input v-model:value="formData.skxqmc" placeholder="请输入上课校区名称" allow-clear />
            </a-form-item>
            <a-form-item label="理论学时：" name="llxs">
                <a-input v-model:value="formData.llxs" placeholder="请输入理论学时" allow-clear />
            </a-form-item>
            <a-form-item label="实践学时：" name="sjxs">
                <a-input v-model:value="formData.sjxs" placeholder="请输入实践学时" allow-clear />
            </a-form-item>
            <a-form-item label="实验学时：" name="syxs">
                <a-input v-model:value="formData.syxs" placeholder="请输入实验学时" allow-clear />
            </a-form-item>
            <a-form-item label="其它学时：" name="qtxs">
                <a-input v-model:value="formData.qtxs" placeholder="请输入其它学时" allow-clear />
            </a-form-item>
        </a-form>
        <template #footer>
            <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
            <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
        </template>
    </a-drawer>
</template>

<script setup name="jwXkxxForm">
    import { cloneDeep } from 'lodash-es'
    import { required } from '@/utils/formRules'
    import jwXkxxApi from '@/api/biz/jwXkxxApi'
    // 抽屉状态
    const visible = ref(false)
    const emit = defineEmits({ successful: null })
    const formRef = ref()
    // 表单数据
    const formData = ref({})
    const submitLoading = ref(false)

    // 打开抽屉
    const onOpen = (record) => {
        visible.value = true
        if (record) {
            let recordData = cloneDeep(record)
            formData.value = Object.assign({}, recordData)
        }
    }
    // 关闭抽屉
    const onClose = () => {
        formRef.value.resetFields()
        formData.value = {}
        visible.value = false
    }
    // 默认要校验的
    const formRules = {
    }
    // 验证并提交数据
    const onSubmit = () => {
        formRef.value
            .validate()
            .then(() => {
                submitLoading.value = true
                const formDataParam = cloneDeep(formData.value)
                jwXkxxApi
                    .jwXkxxSubmitForm(formDataParam, formDataParam.kkdm)
                    .then(() => {
                        onClose()
                        emit('successful')
                    })
                    .finally(() => {
                        submitLoading.value = false
                    })
            })
    }
    // 抛出函数
    defineExpose({
        onOpen
    })
</script>
